import React, {
	Component
} from 'react'
import {
	inject,
	observer
} from 'mobx-react';
import {
	Tools
} from "weaver-mobile";
import {
    withRouter,
    Link,
    Route
} from 'react-router-dom';
import '../../style/resource.less';
import TitlePage from '../coms/TitlePage';
import SearchCondition from './search/SearchCondition';
import SearchList from './list/SearchList';
import has from 'lodash/has';
const getLabel = Tools.getLabel;

@inject('resourceStore')
@withRouter
@observer
export default class MySubordinates extends Component {
	componentDidMount() {
        this.init();
    }
    
	init = () => {
        const {resourceStore, math} = this.props;
        let userId;
        if(math != null && has(math, 'params')){
            const {params} = math;
            if(has(params, 'id'))
            userId = params.id;
        }else if(this.props.userId)
            userId = this.props.userId;
        else{

        }
            
		resourceStore.setHrmId(userId);
		resourceStore.init();
	}

	render() {
		const {
            resourceStore,
            onRowClick,
            showTitle,
            title,
            route
		} = this.props;

        let titleStr;
        if(showTitle){
            if(title != null && title.trim().length  > 0){
                titleStr = title;
            }else{
                const {
                    lastname
                } = resourceStore;
                if(lastname != null && lastname != '')
                    titleStr = `${lastname}${getLabel(500942,'的下属')}`;
            }
        }

        return (
            <TitlePage title={titleStr}>
                <SearchCondition store={resourceStore} route={route}/>
				<SearchList store={resourceStore} onRowClick={onRowClick}/>
            </TitlePage>
        )
	}
}